﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI;
using UFSoft.UBF.UI.ControlModel;

namespace MF_HSD_UIPlug
{

    public class CommonFunction
    { /// <summary>
      /// 设置控件在卡片容器中的布局
      /// </summary>
      /// <param name="container">卡片容器</param>
      /// <param name="ctrl">增加的控件</param>
      /// <param name="x">布局横坐标</param>
      /// <param name="y">布局纵坐标</param>
        public static void Layout(UFSoft.UBF.UI.ControlModel.IContainer container, UFSoft.UBF.UI.ControlModel.IUFControl ctrl, uint x, uint y)
        {
            Layout(container, ctrl, x, y, 1, 1, System.Web.UI.WebControls.Unit.Pixel(0), System.Web.UI.WebControls.Unit.Pixel(0), true);
        }

        /// <summary>
        /// 设置控件在卡片容器中的布局
        /// </summary>
        /// <param name="container">卡片容器</param>
        /// <param name="ctrl">增加的控件</param>
        /// <param name="x">布局横坐标</param>
        /// <param name="y">布局纵坐标</param>
        /// <param name="width">控件宽</param>
        /// <param name="height">控件高</param>
        public static void Layout(UFSoft.UBF.UI.ControlModel.IContainer container, UFSoft.UBF.UI.ControlModel.IUFControl ctrl, uint x, uint y, int width, int height)
        {
            Layout(container, ctrl, x, y, 1, 1, System.Web.UI.WebControls.Unit.Pixel(width), System.Web.UI.WebControls.Unit.Pixel(height), false);
        }





        /// <summary>
        /// 设置控件在卡片容器中的布局
        /// </summary>
        /// <param name="container">卡片容器</param>
        /// <param name="ctrl">增加的控件</param>
        /// <param name="x">布局横坐标</param>
        /// <param name="y">布局纵坐标</param>
        /// <param name="xspan">单元格横向跨度</param>
        /// <param name="yspan">单元格纵向跨度</param>
        /// <param name="width">控件宽</param>
        /// <param name="height">控件高</param>
        /// <param name="isAutoSize">是否自适应大小</param>
        public static void Layout(UFSoft.UBF.UI.ControlModel.IContainer container, UFSoft.UBF.UI.ControlModel.IUFControl ctrl, uint x, uint y, int xspan, int yspan,
            System.Web.UI.WebControls.Unit width, System.Web.UI.WebControls.Unit height, bool isAutoSize)
        {
            UFSoft.UBF.UI.Controls.IGridLayout gl = container.Layout as UFSoft.UBF.UI.Controls.IGridLayout;
            if (gl == null) return;
            UFSoft.UBF.UI.WebControls.GridLayoutInfo glInfo = new UFSoft.UBF.UI.WebControls.GridLayoutInfo((uint)x, (uint)y, (uint)xspan, (uint)yspan, width, height);
            glInfo.AutoSize = isAutoSize;
            gl.Controls.Add((System.Web.UI.Control)ctrl, glInfo);
        }


        public static IUFControl FindControl(UFSoft.UBF.UI.IView.IPart Part, string parentControl, string control)
        {
            IUFCard card = (IUFCard)Part.GetUFControlByName(Part.TopLevelContainer, parentControl);
            if (card == null)
                return null;

            foreach (IUFControl ctrl in card.Controls)
            {
                if (ctrl.ID.Equals(control, StringComparison.OrdinalIgnoreCase))
                {
                    return ctrl;
                }
            }
            return null;
        }

        #region 有问题找不到审批动作的下拉框

        public static IUFDropDownButton FindDropDownButton(UFSoft.UBF.UI.IView.IPart Part, string parentControl, string control)
        {
            IUFDropDownButton MenuList = (IUFDropDownButton)Part.GetUFControlByName(Part.TopLevelContainer, parentControl);
            if (MenuList == null)
                return null;
            return MenuList;
        }

        public static IUFDropDownButton FindDropDownButton(UFSoft.UBF.UI.IView.IPart Part, string ControlName)
        {
            UFSoft.UBF.UI.ControlModel.IUFDropDownButton BtnList = (UFSoft.UBF.UI.ControlModel.IUFDropDownButton)((Control)Part).FindControl(ControlName);
            return BtnList;
        }
        #endregion




        public static void LayoutTask(UFSoft.UBF.UI.ControlModel.IContainer container, UFSoft.UBF.UI.ControlModel.IUFControl ctrl, uint x, uint y, int xspan, int yspan,
            System.Web.UI.WebControls.Unit width, System.Web.UI.WebControls.Unit height, bool isAutoSize)
        {
            UFSoft.UBF.UI.Controls.IGridLayout gl = container.Layout as UFSoft.UBF.UI.Controls.IGridLayout;
            if (gl == null) return;
            UFSoft.UBF.UI.WebControls.GridLayoutInfo glInfo = new UFSoft.UBF.UI.WebControls.GridLayoutInfo((uint)x, (uint)y, (uint)xspan, (uint)yspan, width, height);
            glInfo.AutoSize = isAutoSize;
            gl.Controls.Add((System.Web.UI.Control)ctrl, glInfo);
        }

        /// <summary>
        /// 获取参数设置
        /// </summary>
        /// <param name="ProfileCode"></param>
        /// <returns></returns>
        //public static string GetProfile(string ProfileCode)
        //{
        //    string pV = "";
        //    GetProfileValueProxy bpObj = new GetProfileValueProxy();
        //    bpObj.ProfileCode = ProfileCode;
        //    PVDTOData pVDTOData = bpObj.Do();    // 
        //    if (pVDTOData != null)
        //    {
        //        pV = pVDTOData.ProfileValue;
        //    }
        //    return pV;
        //}
    }
}
